﻿using System.Configuration;

namespace Framework.Config
{
    [ConfigurationCollection(typeof(HandlerElement), AddItemName="handler", CollectionType=ConfigurationElementCollectionType.BasicMap)]
    public class HandlerElementCollection : ConfigurationElementCollection
    {
        public HandlerElement this[int idx]
        {
            get
            {
                return base.BaseGet(idx) as HandlerElement;
            }
            set
            {
                if (base.BaseGet(idx) != null)
                {
                    base.BaseRemoveAt(idx);
                }
                base.BaseAdd(idx, value);
            }
        }

        protected override string ElementName
        {
            get
            {
                return "handler";
            }
        }

        public override ConfigurationElementCollectionType CollectionType
        {
            get
            {
                return ConfigurationElementCollectionType.BasicMap;
            }
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new HandlerElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return (element as HandlerElement).Name;
        }
    }
}
